// @Title        sendMessage
// @Description  消息推送
// @Author       星辰
// @Update
package main

import (
	"bytes"
	"encoding/json"
	"io/ioutil"
	"log"
	"net/http"
	"net/url"
	"strings"
)

var mBuffer *bytes.Buffer //用于在内存中保存日志

// @title         sendToServerChan
// @description   推送消息至TG
// @auth          星辰
// @param
// @return
func sendToServerChan() {
	defer mBuffer.Reset()
	if MyConfig.SCKEY == "" {
		log.Println("未定义消息推送")
		return
	}
	resp, err := http.PostForm(
		"https://api.telegram.org/bot"+MyConfig.SCKEY+"/sendMessage?chat_id=1714132921",
		url.Values{
			"parse_mode": {"Markdown"},
			"text": {"#微博超话签到" + "\n\n" + strings.Replace(mBuffer.String(), "\n", "\n\n", -1 )},
		},
	)

	if err != nil {
		log.Println("消息推送异常："+err.Error())
		return
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Println("消息推送异常："+err.Error())
		return
	}
	var data map[string]interface{}
	print()
	err = json.Unmarshal(body, &data)
	if err != nil {
		log.Println("消息推送读取响应异常："+err.Error())
		return
	}
	//log.Println("推送信息："+data["errmsg"].(string))
}
